{% from '@SyliusAdmin/shared/helper/accordion.html.twig' import accordion %}
{% import '@SyliusAdmin/shared/helper/money.html.twig' as money %}

{% set items = [] %}

<div class="mb-2">
    <div class="card">
        <div class="card-body">
            {% for channel_statistics in this.statistics %}
                {% set channel = channel_statistics.channel %}

                {% set title %}
                    <div class="h3">
                        <span class="badge me-2" style="background-color: {{ channel.color|default('#000') }}"></span>
                        {{ channel.name }}
                    </div>
                {% endset %}

                {% set content %}
                    <div class="row">
                        <div class="col-sm-12 col-md-4 mb-3">
                            <div class="card card-sm">
                                <div class="card-body">
                                    <div class="row align-items-center">
                                        <div class="col-auto">
                                            <span class="bg-gray text-muted avatar">
                                                {{ ux_icon('tabler:shopping-bag') }}
                                            </span>
                                        </div>
                                        <div class="col">
                                            <div>{{ 'sylius.ui.orders'|trans }}</div>
                                            <div class="h2 mb-0 me-2" {{ sylius_test_html_attribute('customer-statistics-' ~ channel.code ~ '-orders-count') }}>{{ channel_statistics.ordersCount }}</div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="col-sm-12 col-md-4 mb-3">
                            <div class="card card-sm">
                                <div class="card-body">
                                    <div class="row align-items-center">
                                        <div class="col-auto">
                                            <span class="bg-gray text-muted avatar">
                                                {{ ux_icon('tabler:coins') }}
                                            </span>
                                        </div>
                                        <div class="col">
                                            <div>{{ 'sylius.ui.total_value_of_orders'|trans }}</div>
                                            <div class="h2 mb-0 me-2" {{ sylius_test_html_attribute('customer-statistics-' ~ channel.code ~ '-orders-total') }}>{{ money.format(channel_statistics.ordersValue, channel.baseCurrency.code) }}</div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="col-sm-12 col-md-4 mb-3">
                            <div class="card card-sm">
                                <div class="card-body">
                                    <div class="row align-items-center">
                                        <div class="col-auto">
                                            <span class="bg-gray text-muted avatar">
                                                {{ ux_icon('tabler:slash') }}
                                            </span>
                                        </div>
                                        <div class="col">
                                            <div>{{ 'sylius.ui.average_order_value'|trans }}</div>
                                            <div class="h2 mb-0 me-2" {{ sylius_test_html_attribute('customer-statistics-' ~ channel.code ~ '-orders-average') }}>{{ money.format(channel_statistics.averageOrderValue, channel.baseCurrency.code) }}</div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                {% endset %}

                {% set open = loop.first ? true : false %}
                {% set items = items|merge([{title: title, content: content, open: open}]) %}
            {% endfor %}

            {% if items is not empty %}
                {{ accordion(items, false, null, true) }}
            {% else %}
                <div class="h3 text-muted" {{ sylius_test_html_attribute('customer-statistics-no-orders') }}>{{ 'sylius.ui.there_are_no_orders_for_this_customer_to_display'|trans }}</div>
            {% endif %}
        </div>
    </div>
</div>
